package chp11;

import java.util.Scanner;

public class Game2 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int myWinCount = 0;//玩家胜的次数
        int compWinCount = 0;//电脑胜的次数
        while (true) {
            System.out.print("\n请出拳:1.剪刀 2.石头 3.布(输入相应数字):");
            int myFist = input.nextInt();
            switch (myFist) {
                case 1:
                    System.out.println("你出拳:剪刀");
                    break;
                case 2:
                    System.out.println("你出拳:石头");
                    break;
                case 3:
                    System.out.println("你出拳:布");
                    break;
            }
            int compFist = (int) (Math.random() * 3 + 1);
            switch (compFist) {
                case 1:
                    System.out.println("电脑出拳:剪刀");
                    break;
                case 2:
                    System.out.println("电脑出拳:石头");
                    break;
                case 3:
                    System.out.println("电脑出拳:布");
                    break;
            }

            //比较胜负
            if (myFist == compFist) {
                System.out.println("结果：平手");
            } else if (myFist == 1 && compFist == 3 || myFist == 2 && compFist == 1 || myFist == 3 && compFist == 2) {
                System.out.println("结果：你赢了");
                myWinCount++;
            } else {
                System.out.println("结果：你输了");
                compWinCount++;
            }

            System.out.print("\n是否开始下一轮(y/n):");
            String answer = input.next();
            if(answer.equals("n")){
                break;
            }
        }
        System.out.println("你 VS 电脑");
        System.out.println(myWinCount +" : " + compWinCount);
    }
}
